<template>
  <div>
    <el-table :data="taskList" stripe border style="width: 100%" empty-text="没有待处理任务">
      <el-table-column prop="tstkno" label="任务号" width="180" />
      <el-table-column prop="tskname" label="任务名称" />
      <el-table-column prop="procname" label="流程号" width="180" />
      <el-table-column prop="nodesn" label="节点" width="180" />
      <el-table-column label="任务状态">
        <template slot-scope="scope">
          {{ key_tskstat[scope.row.tskstat] }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="toTask(scope.row)">处理</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import request from '@/utils/request'
export default {
  data: function() {
    return {
      conditions: [
        {
          field: 'tskstat',
          type: 'ARRAY',
          value: '[0,1]',
          symbol: 'IN'
        }
      ],
      page: {
        current: 1,
        size: 5,
        total: 0
      },
      taskList: []
    }
  },
  computed: {
    key_tskstat: function() {
      const { tskstat = {}} = this.$store.state.directory.directoryItem
      return tskstat
    }
  },
  created() {
    this.query()
    this.directoryUpdate()
  },
  methods: {
    directoryUpdate: function() {
      this.$store.commit('directory/setDirectory', 'tskstat')
    },
    // 转到详细任务信息
    toTask: function(row) {
      this.$router.push({ name: '任务处理', params: row })
    },
    // 每页显示数目发生变化时
    handleSizeChange: function(val) {
      this.page.size = val
      this.page.current = 1
      this.query()
    },
    // 当前页发生变化时
    handleCurrentChange: function(val) {
      this.page.current = val
      this.query()
    },
    query: function() {
      this.$progress.start()
      this.page.conditions = this.conditions
      request({
        url: '/task/tasklist/queryCurrentUserTasks',
        method: 'post',
        data: this.page
      }).then(res => {
        this.$progress.done()
        if (res.result) {
          this.page.total = res.data.total
          this.taskList = res.data.data
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => { this.$progress.done() })
    }
  }
}
</script>
